package com.jprocms.module.cms.enums;

import cn.hutool.core.util.ArrayUtil;
import com.jpro.framework.common.core.IntArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 用户邮箱验证码发送场景的枚举
 *
 * @author JPROCMS
 */
@Getter
@AllArgsConstructor
public enum EmailSceneEnum implements IntArrayValuable {

    MEMBER_LOGIN(1, "会员用户 - 邮箱登陆"),
    MEMBER_UPDATE_MOBILE(2, "会员用户 - 修改邮箱"),
    MEMBER_FORGET_PASSWORD(3, "会员用户 - 忘记密码"),
    MEMBER_REGISTER(4, "会员用户 - 注册");

    public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(EmailSceneEnum::getScene).toArray();

    /**
     * 验证场景的编号
     */
    private final Integer scene;
    /**
     * 描述
     */
    private final String description;

    @Override
    public int[] array() {
        return ARRAYS;
    }

    public static EmailSceneEnum getCodeByScene(Integer scene) {
        return ArrayUtil.firstMatch(sceneEnum -> sceneEnum.getScene().equals(scene),
                values());
    }

}
